import mysql_util as sql_util
import json
from datetime import datetime

if __name__ == '__main__':
    sql = "SELECT distinct o4.CODE orgCode FROM pc_organization o4 WHERE o4.`level` = '4' and o4.enabled = 1 and o4.code not in (select SUBSTRING_INDEX(content, ']', 1)  from pc_icon_config where type = 'temp_permission_8' ) order by o4.code"
    list = sql_util.select_by_sql(sql)
    list = json.loads(list)
    print(list)
    for o in list:
        content = "{}]监控中心,智能环控,智能料塔,生产预警,生产分析,生产录入".format(o['orgCode'])
        # print(content)
        sql = "INSERT INTO pc_icon_config( `flag`, `content`, `type`, `farm_main_type`) " \
              "VALUES ( NULL, '{}', 'temp_permission_8', NULL);".format(content)
        print(sql)
